package org.csu.mypetstore.persistence;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.csu.mypetstore.domain.LineItem;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LineItemMapper extends BaseMapper {
    @Select("SELECT\n" +
            "      ORDERID,\n" +
            "      LINENUM AS lineNumber,\n" +
            "      ITEMID,\n" +
            "      QUANTITY,\n" +
            "      UNITPRICE\n" +
            "    FROM LINEITEM\n" +
            "    WHERE ORDERID = #{orderId}")
    List<LineItem> getLineItemsByOrderId(int orderId);
    @Insert("INSERT INTO LINEITEM (ORDERID, LINENUM, ITEMID, QUANTITY, UNITPRICE)\n" +
            "    VALUES (#{orderId}, #{lineNumber}, #{itemId}, #{quantity}, #{unitPrice})")
    void insertLineItem(LineItem lineItem);
}
